#!/bin/python
import wafdino
from waflib import Task


def options(opt):
    opt.load('compiler_cxx')


def configure(ctx):
    acfg = wafdino.ArduinoConfig('sam')
    acfg.LoadTools(ctx)
    ctx.load('gcc g++')
    ctx.load('objcopy')
    ctx.env.append_value('CXXFLAGS', '-ggdb')



def build(bld):
    from waflib.Tools import cxx
    class cxxprogram(cxx.cxxprogram):
        run_str = '${LINK_CXX} ${LINKFLAGS} ${CXXLNK_SRC_F}${SRC} ${CXXLNK_TGT_F}${TGT[0].abspath()} ${RPATH_ST:RPATH} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${FRAMEWORK_ST:FRAMEWORK} ${ARCH_ST:ARCH} ${STLIB_MARKER} -Wl,--start-group ${STLIBPATH_ST:STLIBPATH} ${STLIB_ST:STLIB} ${LIBPATH_ST:LIBPATH} ${LIB_ST:LIB} ${CRT} -Wl,--end-group -Wl,-Map,crap.map'
    src = bld.path.ant_glob(['arduino/hardware/arduino/sam/cores/arduino/*.(c|cpp)','arduino/hardware/arduino/sam/cores/arduino/USB/*.(c|cpp)', 'arduino/hardware/arduino/sam/variants/arduino_due_x/*.(c|cpp)'])
    print src
    bld.stlib(source = src, target='core', includes='arduino/hardware/arduino/sam/cores/arduino/')

    bld.program(features = 'objcopy', source='main.cpp', objcopy_bfdname='binary', target='app.elf', use = ['core', 'runtime'], includes='arduino/hardware/arduino/sam/cores/arduino/')

